package top.forforever.srb.core.util;

import top.forforever.srb.common.exception.Assert;
import top.forforever.srb.common.result.ResponseEnum;
import top.forforever.srb.common.util.JwtUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @create: 2023/6/5
 * @Description:
 * @FileName: AuthContextHolder
 * @自定义内容：
 */

public class AuthContextHolder {

    public static Long getUserIdAndAuth(HttpServletRequest request) {
        String token = request.getHeader("token");
        Assert.notNull(token, ResponseEnum.LOGIN_AUTH_ERROR);
        Assert.isTrue(JwtUtils.checkToken(token), ResponseEnum.WEIXIN_FETCH_ACCESSTOKEN_ERROR);
        return JwtUtils.getUserId(token);
    }
}
